//
//  RootTabBarController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/8/20.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit
import ESTabBarController_swift

class RootTabBarController: ESTabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addController()
        
    }
    
    //MARK: 添加控制器
    fileprivate func addController() {
        
        //账户
        let accountVC = KMNavigationController.init(rootViewController: AccountViewController())
        accountVC.tabBarItem = ESTabBarItem.init(TabBarBgContentView(),title:account_title,image:#imageLiteral(resourceName: "account_unselect"),selectedImage:#imageLiteral(resourceName: "account_select"))
        
        //信用卡
        let creditCardVC = KMNavigationController.init(rootViewController: CardViewController())
        creditCardVC.tabBarItem = ESTabBarItem.init(TabBarBgContentView(),title:creditCard_title,image:#imageLiteral(resourceName: "creditcard_unselect"),selectedImage:#imageLiteral(resourceName: "creditcard_select"))
        
        //贷款
        let loanVC = KMNavigationController.init(rootViewController: LoanViewController())
        loanVC.tabBarItem = ESTabBarItem.init(TabBarBgContentView(),title:loan_title,image:#imageLiteral(resourceName: "loans_unselect"),selectedImage:#imageLiteral(resourceName: "loans_select"))
        
        //资讯
        let informationVC = KMNavigationController.init(rootViewController: InformationViewController())
        informationVC.tabBarItem = ESTabBarItem.init(TabBarBgContentView(),title:information_title,image:#imageLiteral(resourceName: "information_unselect"),selectedImage:#imageLiteral(resourceName: "information_select"))
    
        //我
        let mineVC = KMNavigationController.init(rootViewController: MineViewController())
        mineVC.tabBarItem = ESTabBarItem.init(TabBarBgContentView(),title:me_title,image:#imageLiteral(resourceName: "mine_unselect"),selectedImage:#imageLiteral(resourceName: "mine_select"))
        
        self.viewControllers = [accountVC,creditCardVC,loanVC,informationVC,mineVC]
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

}

class TabBarBgContentView : ESTabBarItemContentView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //调整每个item边距
        insets = UIEdgeInsets.init(top: -5, left: 0, bottom: 5, right: 0)
        
        //设置默认文字颜色
        textColor = UIColor.lightGray
        //设置选中文字颜色
        highlightTextColor = UIColor.tabBarColor()
        
        //设置默认文字颜色
        iconColor = UIColor.lightGray
        //设置选中图标颜色
        highlightIconColor = UIColor.tabBarColor()
        
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: 重写以下方法调整图片和文本大小位置
    override func updateLayout() {
        super.updateLayout()
        
        //调整图片大小和位置
        imageView.frame.size = CGSize.init(width: 30, height: 30)
        imageView.center.x = self.center.x
        
        //设置字体大小和位置
        titleLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 13))
        titleLabel.sizeToFit()
        titleLabel.center.x = self.center.x
        
        
    }
    
    
}











